package cn.wolfcode.demo;


import org.activiti.engine.*;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;

import java.util.List;

//并行网关
public class demo7 {
    @Test
    public void testDemo(){
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        System.out.println(processEngine);
    }
    @Test
    public void testDeploy(){
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        RepositoryService repositoryService = processEngine.getRepositoryService();
        Deployment deployment = repositoryService.createDeployment().addClasspathResource("bpnm/ParallelGateway.bpmn")
                .addClasspathResource("bpnm/ParallelGateway.png")
                .name("并行网关").deploy();
        System.out.println(deployment.getId() + "并行网关ID");
        System.out.println("并行网关名称" + deployment.getName());
    }
    @Test
    public void testStartProcess(){
        //创建ProcessEngine对象
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //获取RuntimeService对象
        RuntimeService runtimeService = processEngine.getRuntimeService();

        //根据流程定义的key启动流程实例,这个key是在定义bpmn的时候设置的
        ProcessInstance instance = runtimeService.startProcessInstanceByKey("ParallelGateway");
        //获取流程实例的相关信息
        System.out.println("流程定义的id = " + instance.getProcessDefinitionId());
        System.out.println("流程实例的id = " + instance.getId());
    }

@Test
    public void testCompleteTask(){

    ProcessEngine processEngines = ProcessEngines.getDefaultProcessEngine();
    TaskService taskService = processEngines.getTaskService();
    List<Task> list = taskService.createTaskQuery().processDefinitionKey("ParallelGateway")
            .taskAssignee("lisi").list();
    for (Task task : list) {
        taskService.complete(task.getId());
    }

}
}
